package com.eascs.workflow.util;

import java.util.List;

import org.springframework.stereotype.Service;
import com.eascs.app.monitor.warn.ServerWarn;
import com.eascs.app.monitor.warn.ServiceWarnMonitor;
import com.eascs.app.monitor.warn.WarnStatus;
import com.eascs.workflow.common.dao.BaseDao;

@Service
public class WFServiceWarnMonitor extends BaseDao implements ServiceWarnMonitor {

	@Override
	public ServerWarn getServerWarn() throws Exception {
		ServerWarn sw = new ServerWarn();
		StringBuffer sb = new StringBuffer();
		String sql = "select receive_telphone,sms_error from wf_message where  status = '0' and  counts>0 and  send_time > DATE_ADD(now(),INTERVAL 5 MINUTE ) ";
		List<Object[]> list = findObjectsList(sql);
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				Object[] o = list.get(i);
				String s = "手机号：" + o[0] + "失败原因：" + o[1] + ";";
				sb.append(s);
			}
		}
		sw.setWarnMessage(sb.toString());
		sw.setWarnStatus(WarnStatus.ERROR);
		return sw;
	}

	@Override
	public String getServiceName() {
		return "workflow";
	}

}
